package com.hutianao.gqgl.post.control;

import com.hutianao.gqgl.mybatis.entity.PtJobEntity;
import com.hutianao.gqgl.mybatis.entity.PtPostEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PaddingEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PadingRstType;
import com.hutianao.gqgl.mybatis.ztree.ZtreeEntity;
import com.hutianao.gqgl.post.entity.SearchPostEntity;
import com.hutianao.gqgl.post.service.PostService;
import com.hutianao.gqgl.spring.tag.entity.DictTagEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.jdbc.UncategorizedSQLException;
import com.hutianao.gqgl.mybatis.flexigrid.PaddingEntity;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/job")
public class PostController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private PostService postService;

    @RequestMapping("/postPage")
    private String postPage(HttpServletRequest request){
        List<DictTagEntity> roleList=postService.queryRoleList();
        List<DictTagEntity> organList=postService.queryOrganList();
        request.getSession().setAttribute("roleList",roleList);
        request.getSession().setAttribute("organList",organList);
        return "post/postPage";

    }
    @RequestMapping("/queryLeftOrganTree")
    @ResponseBody
    private List<ZtreeEntity> queryLeftOrganTree(){
        return postService.queryLeftOrganTree();
    }

    @RequestMapping("/queryPostInfoListByOrgan")
    @ResponseBody
    public PadingRstType<PtPostEntity> queryPostInfoListByOrgan(SearchPostEntity search, PaddingEntity padding){
        logger.info(search);
        logger.info(padding);
        PadingRstType<PtPostEntity> padingRstType=postService.queryPostInfoListByOrgan(search,padding);
        return padingRstType;
    }

    @RequestMapping("/queryPostInfoById")
    @ResponseBody
    public PtPostEntity queryPostInfoById(@RequestParam("dutyId") String dutyId){
        logger.info("dutyId:"+dutyId);
        PtPostEntity ptPostEntity=postService.queryPostInfoById(dutyId);
        return ptPostEntity;
    }

    @RequestMapping("/postPageDetail")
    private String postPageDetail(@RequestParam("dutyId") String dutyId,HttpServletRequest request) {
        logger.info("dutyId:" + dutyId);
        request.getSession().setAttribute("dutyId", dutyId);

        return "post/postPageDetail";
    }


}
